package com.shoulder.boot.process.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoulder.boot.process.dto.FormAddDTO;
import com.shoulder.boot.process.dto.FormModDTO;
import com.shoulder.boot.process.vo.FormVo;
import com.shoulder.boot.process.dto.FormQueryDTO;
import com.shoulder.boot.process.entity.Form;
import com.shoulder.boot.process.service.FormService;
import com.shoulder.core.api.ApiResult;
import com.shoulder.log.annotation.LogAnnotation;
import com.shoulder.core.fetch.BaseIds;
import com.shoulder.core.page.PageSchema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import java.util.List;

/**
* 表单信息管理
*/
@RestController
@AllArgsConstructor
@RequestMapping("/admin/api/v1/process/form")
public class FormController {

    private final FormService formService;

    /**
    * 添加表单信息
    *
    * @param addDTO 表单信息添加请求体
    * @return ApiResult<Object>
    * @author 596767880@qq.com
    */
    @PostMapping
    @LogAnnotation(type = "添加表单信息")
    public ApiResult<Object> add(@RequestBody @Validated FormAddDTO addDTO) {
        this.formService.add(addDTO);
        return ApiResult.ok();
    }

    /**
    * 修改表单信息
    *
    * @param modDTO 表单信息修改请求体
    * @return ApiResult<Object>
    * @author 596767880@qq.com
    */
    @PutMapping
    @LogAnnotation(type = "修改表单信息")
    public ApiResult<Object> mod(@RequestBody @Validated FormModDTO modDTO) {
        this.formService.mod(modDTO);
        return ApiResult.ok();
    }

    /**
    * 查询表单信息分页数据
    *
    * @param queryDTO 表单信息查询请求体
    * @return 表单信息分页数据
    * @author 596767880@qq.com
    */
    @LogAnnotation(type = "表单信息分页查询", record = false)
    @PostMapping("/page")
    public ApiResult<PageSchema<FormVo>> pageQuery(@RequestBody FormQueryDTO queryDTO) {
        Page<FormVo> page = this.formService.pageQuery(queryDTO);
        return ApiResult.ok(new PageSchema<>(page.getTotal(), page.getRecords()));
    }

    /**
    * 查询表单信息列表数据
    *
    * @param queryDTO 表单信息查询请求体
    * @return 表单信息列表数据
    * @author 596767880@qq.com
    */
    @LogAnnotation(type = "表单信息列表查询", record = false)
    @PostMapping("/list")
    public ApiResult<List<FormVo>> list(@RequestBody FormQueryDTO queryDTO) {
        List<FormVo> list = this.formService.listQuery(queryDTO);
        return ApiResult.ok(list);
    }

    /**
    * 批量删除表单信息
    *
    * @param baseIds  表单信息id集合
    * @return ApiResult<Object>
    * @author 596767880@qq.com
    */
    @PostMapping("/rm")
    @LogAnnotation(type = "批量删除表单信息")
    public ApiResult<Object> delete(@RequestBody @Validated BaseIds<String> baseIds) {
        this.formService.batchDel(baseIds);
        return ApiResult.ok();
    }


    /**
    * 根据id删除表单信息
    *
    * @param id 表单信息id
    * @return ApiResult<Object>
    * @author 596767880@qq.com
    */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除表单信息")
    public ApiResult<Object> del(@PathVariable String id) {
        this.formService.del(id);
        return ApiResult.ok();
    }


    /**
    * 批量查询表单信息
    *
    * @param baseIds  表单信息id集合
    * @return 表单信息列表数据
    * @author 596767880@qq.com
    */
    @PostMapping("/look")
    @LogAnnotation(type = "批量查询表单信息", record = false)
    public ApiResult<List<FormVo>> looks(@RequestBody BaseIds<String> baseIds) {
        List<FormVo> list = this.formService.looks(baseIds);
        return ApiResult.ok(list);
    }

    /**
    * 根据id获取表单信息
    *
    * @param id 表单信息id
    * @return 表单信息
    * @author 596767880@qq.com
    */
    @GetMapping("/{id}")
    @LogAnnotation(type = "根据id查询表单信息", record = false)
    public ApiResult<FormVo> look(@PathVariable String id) {
        FormVo look = this.formService.look(id);
        return ApiResult.ok(look);
    }
}
